<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        border: 0;
        box-sizing: border-box;
    }

    .box {
        position: relative;
        width: 560px;
        height: 400px;
        margin: 50px auto 0;
        background-color: #000;
    }

    .box img {
        width: 100%;
        height: 100%;
        display: block;
    }

    .box .bottom {
        position: absolute;
        bottom: 0;
        left: 0;
        padding-left: 5px;
        width: 100%;
        height: 80px;
        background-color: rgb(100, 67, 68);
    }

    .box .bottom .wrapper {
        height: 50px;
        width: 100%;
    }

    .box .bottom ul {
        display: flex;
        list-style: none;
        align-items: center;
    }

    .box .bottom li {
        width: 8px;
        height: 8px;
        margin: 4px;
        border-radius: 50%;
        background-color: #fff;
        opacity: 0.1;
    }

    .box .bottom li.active {
        width: 10px;
        height: 10px;
        opacity: 1;
    }

    .box .bottom .wrapper h3 {
        float: left;
        height: 50px;
        line-height: 50px;
        color: white;
    }

    .box .bottom .wrapper button {
        float: right;
        width: 30px;
        height: 30px;
        line-height: 30px;
        color: white;
        margin-top: 8px;
        margin-right: 8px;
        appearance: none;
        cursor: pointer;
        background-color: rgba(255, 255, 255, 0.1);
    }

    .box .bottom .wrapper button:hover {
        background-color: rgba(255, 255, 255, 0.2);
    }
</style>

<body>
    <div class="box">
        <img src="./imgs/slider01.jpg" alt="">
        <div class="bottom">
            <div class="wrapper">
                <h3>对人类来说会不会太超前了</h3>
                <button class="right">&gt;</button>
                <button class="left">&lt;</button>
            </div>
            <ul>
                <li class="active"></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
                <li></li>
            </ul>

        </div>
    </div>

    <script>
        const sliderData = [
            { url: './imgs/slider01.jpg', title: '对人类来说会不会太超前了？', color: 'rgb(100, 67, 68)' },
            { url: './imgs/slider02.jpg', title: '开启剑与雪的黑暗传说！', color: 'rgb(43, 35, 26)' },
            { url: './imgs/slider03.jpg', title: '真正的jo厨出现了！', color: 'rgb(36, 31, 33)' },
            { url: './imgs/slider04.jpg', title: '李玉刚：让世界通过B站看到东方大国文化', color: 'rgb(139, 98, 66)' },
            { url: './imgs/slider05.jpg', title: '快来分享你的寒假日常吧~', color: 'rgb(67, 90, 92)' },
            { url: './imgs/slider06.jpg', title: '哔哩哔哩小年YEAH', color: 'rgb(166, 131, 143)' },
            { url: './imgs/slider07.jpg', title: '一站式解决你的电脑配置问题！！！', color: 'rgb(53, 29, 25)' },
            { url: './imgs/slider08.jpg', title: '谁不想和小猫咪贴贴呢！', color: 'rgb(99, 72, 114)' },
        ]
        let currentIndex = 0
        const box = document.querySelector('.box')
        const img = document.querySelector('.box img')
        const h3 = document.querySelector('.box .bottom .wrapper h3')
        const bottom = document.querySelector('.box .bottom')
        const left = document.querySelector('.left')
        const right = document.querySelector('.right')

        function change(){
            img.src = sliderData[currentIndex].url
            h3.innerHTML = sliderData[currentIndex].title
            bottom.style.backgroundColor = sliderData[currentIndex].color
            document.querySelector('.box .bottom li.active').classList.remove('active')
            document.querySelector(`.box .bottom li:nth-child(${currentIndex + 1})`).classList.add('active')
        }
        function transform() {
            currentIndex += 1
            if (currentIndex === sliderData.length) currentIndex = 0
            change()
        }
        let id = setInterval(transform, 1000)
        left.addEventListener('click', function(e){
            currentIndex -= 1
            if (currentIndex < 0) currentIndex = sliderData.length - 1
            change()
        })
        right.addEventListener('click', function(e){
            transform()
        })
        box.addEventListener('mouseenter', function(){
            clearInterval(id)
        })
        box.addEventListener('mouseleave', function(){
            id = setInterval(transform, 1000)
        })
    </script>

</body>

</html>